home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include "defs.h"
- #include "matrix.h"
-
- har *progname;
- har *filename;
- ixrect *pr1, *pr2;
-
- #ifdef STANDALONE
- ain(argc, argv, envp)
- #else
- ransform_main(argc, argv, envp)
- #endif
- int argc;
- char **argv;
- char **envp;
- {
- register int i, j;
- float a, xs, ys;
- int x, y;
- int rotation, shearing;
- int levels;
- int max_xsize, min_xsize, max_ysize, min_ysize, tr_xsize, tr_ysize;
- VECTOR start, stop;
- VECTOR tr_start, tr_stop;
- VECTOR top_left, top_right, bottom_left, bottom_right;
- VECTOR tr_top_left, tr_top_right, tr_bottom_left, tr_bottom_right;
- MATRIX transform;
- colormap_t colormap;
-
- warning("THIS CODE STILL UNDER DEVELOPMENT\nDO NOT TRUST");
- a = M_PI / 2.;
- xs = ys = 0.;
- x = y = 0;
- rotation = shearing = FALSE;
- progname = strsave(argv[0]);
- parse_profile(&argc, argv, envp);
-
- while ((gc = getopt(argc, argv, "X:Y:a:x:y:")) != EOF)
- switch (gc) {
- case 'x':
- if (!shearing) {
- rotation = TRUE;
- x = atoi(optarg);
- } else
- error("Cannot rotate and shear in same invocation");
- break;
- case 'y':
- if (!shearing) {
- rotation = TRUE;
- y = atoi(optarg);
- } else
- error("Cannot rotate and shear in same invocation");
- break;
- case 'a':
- if (!shearing) {
- rotation = TRUE;
- a = atof(optarg);
- } else
- error("Cannot rotate and shear in same invocation");
- break;
- case 'X':
- if (!rotation) {
- shearing = TRUE;
- xs = atof(optarg);
- } else
- error("Cannot rotate and shear in same invocation");
- break;
- case 'Y':
- if (!rotation) {
- shearing = TRUE;
- ys = atof(optarg);
- } else
- error("Cannot rotate and shear in same invocation");
- break;
- case '?':
- errflag++;
- break;
- }
-
- if (errflag)
- error((char *) 0, "Usage: %s: [[-x xcoord] [-y ycoord] [-a angle]] | [[-X xshear] [-Y yshear]] [infile] [outfile]\n", progname);
-
- for (stream = 0; optind < argc; stream++, optind++)
- if (stream < 2 && strcmp(argv[optind], "-") != 0)
- if (freopen(argv[optind], mode[stream], f[stream]) == NULL)
- error("%s %s", PR_IO_ERR_INFILE, argv[optind]);
-
- if ((pr1 = pr_load(stdin, &colormap)) == NULL)
- error(PR_IO_ERR_RASREAD);
-
- top_left = vinit(0., 0., 0., 1.);
- top_right = vinit((double) pr1->pr_size.x, 0., 0., 1.);
- bottom_right = vinit((double) pr1->pr_size.x, (double) pr1->pr_size.y, 0., 1.);
- bottom_left = vinit(0., (double) pr1->pr_size.y, 0., 1.);
-
- warning("top_left = ");
- dbgvprint(top_left);
- warning("top_right = ");
- dbgvprint(top_right);
- warning("bottom_right = ");
- dbgvprint(bottom_right);
- warning("bottom_left = ");
- dbgvprint(bottom_left);
-
- if (rotation)
- transform = minit(cos(a), sin(a), 0., 0., -sin(a), cos(a), 0., 0., (1 - cos(a)) * x + y * sin(a), (1 - cos(a)) * y - x * sin(a), 1., 0., 0., 0., 0., 1.);
- else
- transform = minit(1., ys, 0., 0., xs, 1., 0., 0., 0., 0., 1., 0., 0., 0., 0., 1.);
-
- dbgmprint(transform);
- tr_top_left = vnil();
- tr_top_right = vnil();
- tr_bottom_left = vnil();
- tr_bottom_right = vnil();
-
- vmult(top_left, transform, tr_top_left);
- vmult(top_right, transform, tr_top_right);
- vmult(bottom_left, transform, tr_bottom_left);
- vmult(bottom_right, transform, tr_bottom_right);
-
- warning("tr_top_left = ");
- dbgvprint(tr_top_left);
-
- warning("tr_top_right = ");
- dbgvprint(tr_top_right);
-
- warning("tr_bottom_right = ");
- dbgvprint(tr_bottom_right);
-
- warning("tr_bottom_left = ");
- dbgvprint(tr_bottom_left);
-
- max_xsize = (int) MAX(tr_top_left[0], tr_top_right[0]);
- max_xsize = (int) MAX(max_xsize, tr_bottom_left[0]);
- max_xsize = (int) MAX(max_xsize, tr_bottom_right[0]);
-
- min_xsize = (int) MIN(tr_top_left[0], tr_top_right[0]);
- min_xsize = (int) MIN(min_xsize, tr_bottom_left[0]);
- min_xsize = (int) MIN(min_xsize, tr_bottom_right[0]);
-
- max_ysize = (int) MAX(tr_top_left[1], tr_top_right[1]);
- max_ysize = (int) MAX(max_ysize, tr_bottom_left[1]);
- max_ysize = (int) MAX(max_ysize, tr_bottom_right[1]);
-
- min_ysize = (int) MIN(tr_top_left[1], tr_top_right[1]);
- min_ysize = (int) MIN(min_ysize, tr_bottom_left[1]);
- min_ysize = (int) MIN(min_ysize, tr_bottom_right[1]);
-
- tr_xsize = abs(max_xsize - min_xsize);
- tr_ysize = abs(max_ysize - min_xsize);
-
- warning("xsize = %d, ysize = %d", tr_xsize, tr_ysize);
- warning("minxsize = %d, min_ysize = %d", min_xsize, min_ysize);
-
- if ((pr2 = mem_create(tr_xsize, tr_ysize, pr1->pr_depth)) == NULL)
- error("mem_create returned NULL");
-
- tr_start = vnil();
- tr_stop = vnil();
- for (j = 0; j < pr1->pr_size.y; j++) {
- start = vinit(0., (double) j, 0., 1.);
- stop = vinit((double) (pr1->pr_size.x), (double) j, 0., 1.);
- vmult(start, transform, tr_start);
- tr_start[0] += abs(min_xsize);
- tr_start[1] += abs(min_ysize);
- vmult(stop, transform, tr_stop);
- tr_stop[0] += abs(min_xsize);
- tr_stop[1] += abs(min_ysize);
- bres_line((int) tr_start[0], (int) tr_start[1], (int) tr_stop[0], (int) tr_stop[1], j);
- }
-
- pr_dump(pr2, stdout, &colormap, RT_STANDARD, 0);
- }
- #define SIGN(a) ((a<0)?-1:((a>0)?1:0))
-
- /* line end pts are (x1, y1) & (x2, y2). Assumed not equal */
- res_line(x1, y1, x2, y2, iny)
- int x1, y1, x2, y2, iny;
- {
- register int i;
- int temp;
- int x, y;
- int dx, dy, s1, s2, e, interchange;
-
- x = x1;
- y = y1;
- dx = abs(x2 - x1);
- dy = abs(y2 - y1);
- s1 = SIGN(x2 - x1);
- s2 = SIGN(y2 - y1);
-
- if (dy > dx) {
- temp = dx;
- dx = dy;
- dy = temp;
- interchange = FALSE;
- } else
- interchange = TRUE;
-
- e = 2 * dy - dx;
-
- for (i = 0; i < dx; i++) {
- pr_put(pr2, x, y, pr_get(pr1, i, iny));
- while (e >= 0) {
- if (interchange)
- x += s1;
- else
- y += s2;
- e -= 2 * dx;
- }
- if (interchange)
- y += s2;
- else
- x += s1;
- e += 2 * dy;
- }
- }
-